/**
 * Created by huangxiaolu on 2014/4/16.
 */
var http = require('http');
var httpProxy = require('http-proxy');
var https = require('https');
var url = require('url');
var proxy = httpProxy.createProxyServer();

var server = http.createServer(function (req,res)
{
    //req.url=req.url.replace('10.8.2.111','10.8.14.28:8080');//('localhost:8800/html5/Account','m.fat19.qa.nt.ctripcorp.com/html5/Account');
    //console.log(req.url);
    var target;
    if (req.url.indexOf('/restapi/')!==-1||req.url.indexOf('/api/')!==-1)
    {

        target = req.url.replace('10.8.2.111','10.8.14.28:8080');
        console.log(target);
    }
    else
    {
        target = req.url;
        //proxy.web(req,res,{target:req.url});//"http://localhost:3001"});
    }
    proxy.web(req,res,{target:target});
})
var port = process.env.PORT||3000
server.listen(port);
console.log("server is listening on %s",port);